package com.sb.registration.component.service;

import java.io.IOException;

import javax.jws.WebService;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import com.sb.registration.component.exceptions.DatastoreSystemException;
import com.sb.registration.component.exceptions.UserAlreadyExistsException;
import com.sb.registration.component.exceptions.UserDoesNotExistException;
import com.sb.registration.component.model.UserRegistrationServiceResult;
import com.sb.registration.component.model.UserWrapper;

/**
 * User Registration Service interface to expose this library as an Web Service for external devices to call.
 * This will allow modular architecture which are loosely coupled and a scalable solution. 
 * 
 * @author gautam.amitkumar@gmail.com
 *
 */
@WebService
@Path("/")
@Produces({"application/json", "application/xml"})
public interface UserRegistrationService {

	/**
	 * Method to register/add users into xml data repository
	 * 
	 * @param userData
	 * @throws UserAlreadyExistsException
	 * @throws DatastoreSystemException
	 */
    @POST
    @Path("/register")
    UserRegistrationServiceResult addUser(UserWrapper userData);
	
    /**
     * Method to update existing users
     * 
     * @param userData
     * @throws DatastoreSystemException
     * @throws UserDoesNotExistException
     */
    @POST
    @Path("/updateuser")
    UserRegistrationServiceResult updateUser(UserWrapper userData);
	
    /**
     * Method to delete existing users based on email id provided.
     * 
     * Below method should a DELETE operation normally for applications, but to keep easy usage and testing
     * for this sample exercise, its been kept as GET method to easily call via browser
     * 
     * @param emailId
     * @throws DatastoreSystemException
     * @throws UserDoesNotExistException
     */
    @GET
    @Path("/delete/{emailId}")
    UserRegistrationServiceResult deleteUser(@PathParam("emailId") String emailId);
	
    /**
     * Method to return all users available in the repository
     * 
     * @return List<UserWrapper>
     */
    @GET
    @Path("/allusers")
    UserRegistrationServiceResult fetchAllUsers();
	
    /**
     * Method to retrieve user on the basis of email id provided.
     * 
     * @param emailId
     * @return UserWrapper
     */
    @GET
    @Path("/user/{emailid}")
    UserRegistrationServiceResult getUser(@PathParam("emailid") String emailId);
	
    /**
     * Method to clear all existing users from the repository
     * 
     * @throws IOException
     * @throws DatastoreSystemException
     */
    @GET
    @Path("/user/clear")
    UserRegistrationServiceResult clearAll();
}
